import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;

public class SonJFrame extends JFrame implements ActionListener, KeyListener {
    static int winP=1;
    static int count1=0;
    static int count2=0;

    public SonJFrame(){
        initJFrame();

        createButton();

        addKeyListener(this);
    }

    private void initJFrame(){
        setSize(500,500);
        setTitle("自律的男生制作的小游戏");
        setLocationRelativeTo(null);
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        setLayout(null);
        setFocusable(true);
        requestFocusInWindow();

        JLabel text=new JLabel("本局红方胜利！");
        JLabel text2=new JLabel("本局蓝方胜利！");
        text.setFont(new Font("微软雅黑",0,50));
        text.setBounds(90,180,500,70);
        text2.setFont(new Font("微软雅黑",0,50));
        text2.setBounds(90,180,500,70);
        if(winP==1){
            add(text);
            count1++;
        }
        if(winP==2){
            add(text2);
            count2++;
        }

        JLabel score1;
        JLabel score2;
        if(count1<=9){
            score1=new JLabel("0"+count1);
        }else {
            score1=new JLabel(String.valueOf(count1));
        }
        if(count2<=9){
            score2=new JLabel("0"+count2);
        }else {
            score2=new JLabel(String.valueOf(count2));
        }
        score1.setFont(new Font("微软雅黑",0,150));
        score2.setFont(new Font("微软雅黑",0,150));
        score1.setForeground(Color.RED);
        score2.setForeground(Color.BLUE);
        score1.setBounds(30,20,200,200);
        score2.setBounds(300,20,200,200);
        add(score1);
        add(score2);
        JLabel bi=new JLabel(":");
        bi.setFont(new Font("微软雅黑",0,170));
        bi.setBounds(230,5,200,200);
        add(bi);
    }

    private void createButton(){
        JButton jButton=new JButton("继续游戏(或R键)");
        jButton.setFont(new Font("微软雅黑", Font.BOLD, 20));
        jButton.setBounds(100,290,300,120);
        jButton.addActionListener(this);
        add(jButton);
    }

    @Override
    public void actionPerformed(ActionEvent e) {
        String command=e.getActionCommand();

        switch (command){
            case "继续游戏(或R键)":
                dispose();
                new GameJFrameT();
                break;
        }
    }

    @Override
    public void keyTyped(KeyEvent e) {

    }

    @Override
    public void keyPressed(KeyEvent e) {
        if(e.getKeyCode()==KeyEvent.VK_R){
            dispose();
            new GameJFrameT();
        }
    }

    @Override
    public void keyReleased(KeyEvent e) {

    }
}
